using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPTFOLGE
    {
        public DataRow Convert2PTFOLGE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPTFOLGE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PTFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PTFPAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["PTFPAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["PTFPAFOLGE"] = " ".PadRight(3 ); 
         dwReturn["PTFNEUB"] = " ".PadRight(8 ); 
         dwReturn["PTFNEUD"] = " ".PadRight(0 ); 
         dwReturn["PTFAENB"] = " ".PadRight(8 ); 
         dwReturn["PTFAEND"] = " ".PadRight(0 ); 
         dwReturn["PTFAENZL"] = " ".PadRight(0 ); 
         dwReturn["PTFSTATUS"] = " ".PadRight(1 ); 
         dwReturn["PTFPKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["PTFPKST"] = " ".PadRight(4 ); 
         dwReturn["PTFMTYP"] = " ".PadRight(8 ); 
         dwReturn["PTFAGANG"] = " ".PadRight(15 ); 
         dwReturn["PTFEVARHNR"] = " ".PadRight(2 ); 
         dwReturn["PTFEVARUNR"] = " ".PadRight(2 ); 
         dwReturn["PTFENDDAT"] = " ".PadRight(0 ); 
         dwReturn["PTFSME"] = " ".PadRight(1 ); 
         dwReturn["PTFSMG1"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG2"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG3"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG4"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG5"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG6"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG7"] = " ".PadRight(0 ); 
         dwReturn["PTFSMG8"] = " ".PadRight(0 ); 
         dwReturn["PTFRUESTZT"] = " ".PadRight(0 ); 
         dwReturn["PTFBEARBZT"] = " ".PadRight(0 ); 
         dwReturn["PTFVERWZT"] = " ".PadRight(0 ); 
         dwReturn["PTFRAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["PTFRAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["PTFRAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["PTFRAFOLGE"] = " ".PadRight(3 ); 
         dwReturn["PTFKETTANZ"] = " ".PadRight(0 ); 
         dwReturn["PTFKETTMTR"] = " ".PadRight(0 ); 
         dwReturn["PTFFILLER"] = " ".PadRight(38 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPTFOLGE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePTFOLGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPTFOLGE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPTFOLGE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPTFOLGE(dwLocal, ITXDBVERSION);
            }
            UpdatePTFOLGE(dwLocal);
        }
        public void InsertPTFOLGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PTFOLGE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPTFOLGE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PTFOLGE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PTFOLGE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PTFOLGE";
            Return = Result;
            return Return;
        }
        public void DeletePTFOLGE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PTFOLGE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePTFOLGE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PTFOLGE SET "
                    +"PTFMANDANT= :PTFMANDANT,"
                    +"PTFPAUFKRS= :PTFPAUFKRS,"
                    +"PTFPAUFLFD= :PTFPAUFLFD,"
                    +"PTFPAFOLGE= :PTFPAFOLGE,"
                    +"PTFNEUB= :PTFNEUB,"
                    +"PTFNEUD= :PTFNEUD,"
                    +"PTFAENB= :PTFAENB,"
                    +"PTFAEND= :PTFAEND,"
                    +"PTFAENZL= :PTFAENZL,"
                    +"PTFSTATUS= :PTFSTATUS,"
                    +"PTFPKSTKRS= :PTFPKSTKRS,"
                    +"PTFPKST= :PTFPKST,"
                    +"PTFMTYP= :PTFMTYP,"
                    +"PTFAGANG= :PTFAGANG,"
                    +"PTFEVARHNR= :PTFEVARHNR,"
                    +"PTFEVARUNR= :PTFEVARUNR,"
                    +"PTFENDDAT= :PTFENDDAT,"
                    +"PTFSME= :PTFSME,"
                    +"PTFSMG1= :PTFSMG1,"
                    +"PTFSMG2= :PTFSMG2,"
                    +"PTFSMG3= :PTFSMG3,"
                    +"PTFSMG4= :PTFSMG4,"
                    +"PTFSMG5= :PTFSMG5,"
                    +"PTFSMG6= :PTFSMG6,"
                    +"PTFSMG7= :PTFSMG7,"
                    +"PTFSMG8= :PTFSMG8,"
                    +"PTFRUESTZT= :PTFRUESTZT,"
                    +"PTFBEARBZT= :PTFBEARBZT,"
                    +"PTFVERWZT= :PTFVERWZT,"
                    +"PTFRAUFKRS= :PTFRAUFKRS,"
                    +"PTFRAUFLFD= :PTFRAUFLFD,"
                    +"PTFRAUFPOS= :PTFRAUFPOS,"
                    +"PTFRAFOLGE= :PTFRAFOLGE,"
                    +"PTFKETTANZ= :PTFKETTANZ,"
                    +"PTFKETTMTR= :PTFKETTMTR,"
                    +"PTFFILLER= :PTFFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PTFMANDANT", OracleType.NVarChar).Value = dwData["PTFMANDANT"].ToString(); 
          or1.Parameters.Add("PTFPAUFKRS", OracleType.NVarChar).Value = dwData["PTFPAUFKRS"].ToString(); 
          or1.Parameters.Add("PTFPAUFLFD", OracleType.NVarChar).Value = dwData["PTFPAUFLFD"].ToString(); 
          or1.Parameters.Add("PTFPAFOLGE", OracleType.NVarChar).Value = dwData["PTFPAFOLGE"].ToString(); 
          or1.Parameters.Add("PTFNEUB", OracleType.NVarChar).Value = dwData["PTFNEUB"].ToString(); 
          or1.Parameters.Add("PTFNEUD", OracleType.NVarChar).Value = dwData["PTFNEUD"].ToString(); 
          or1.Parameters.Add("PTFAENB", OracleType.NVarChar).Value = dwData["PTFAENB"].ToString(); 
          or1.Parameters.Add("PTFAEND", OracleType.NVarChar).Value = dwData["PTFAEND"].ToString(); 
          or1.Parameters.Add("PTFAENZL", OracleType.NVarChar).Value = dwData["PTFAENZL"].ToString(); 
          or1.Parameters.Add("PTFSTATUS", OracleType.NVarChar).Value = dwData["PTFSTATUS"].ToString(); 
          or1.Parameters.Add("PTFPKSTKRS", OracleType.NVarChar).Value = dwData["PTFPKSTKRS"].ToString(); 
          or1.Parameters.Add("PTFPKST", OracleType.NVarChar).Value = dwData["PTFPKST"].ToString(); 
          or1.Parameters.Add("PTFMTYP", OracleType.NVarChar).Value = dwData["PTFMTYP"].ToString(); 
          or1.Parameters.Add("PTFAGANG", OracleType.NVarChar).Value = dwData["PTFAGANG"].ToString(); 
          or1.Parameters.Add("PTFEVARHNR", OracleType.NVarChar).Value = dwData["PTFEVARHNR"].ToString(); 
          or1.Parameters.Add("PTFEVARUNR", OracleType.NVarChar).Value = dwData["PTFEVARUNR"].ToString(); 
          or1.Parameters.Add("PTFENDDAT", OracleType.NVarChar).Value = dwData["PTFENDDAT"].ToString(); 
          or1.Parameters.Add("PTFSME", OracleType.NVarChar).Value = dwData["PTFSME"].ToString(); 
          or1.Parameters.Add("PTFSMG1", OracleType.NVarChar).Value = dwData["PTFSMG1"].ToString(); 
          or1.Parameters.Add("PTFSMG2", OracleType.NVarChar).Value = dwData["PTFSMG2"].ToString(); 
          or1.Parameters.Add("PTFSMG3", OracleType.NVarChar).Value = dwData["PTFSMG3"].ToString(); 
          or1.Parameters.Add("PTFSMG4", OracleType.NVarChar).Value = dwData["PTFSMG4"].ToString(); 
          or1.Parameters.Add("PTFSMG5", OracleType.NVarChar).Value = dwData["PTFSMG5"].ToString(); 
          or1.Parameters.Add("PTFSMG6", OracleType.NVarChar).Value = dwData["PTFSMG6"].ToString(); 
          or1.Parameters.Add("PTFSMG7", OracleType.NVarChar).Value = dwData["PTFSMG7"].ToString(); 
          or1.Parameters.Add("PTFSMG8", OracleType.NVarChar).Value = dwData["PTFSMG8"].ToString(); 
          or1.Parameters.Add("PTFRUESTZT", OracleType.NVarChar).Value = dwData["PTFRUESTZT"].ToString(); 
          or1.Parameters.Add("PTFBEARBZT", OracleType.NVarChar).Value = dwData["PTFBEARBZT"].ToString(); 
          or1.Parameters.Add("PTFVERWZT", OracleType.NVarChar).Value = dwData["PTFVERWZT"].ToString(); 
          or1.Parameters.Add("PTFRAUFKRS", OracleType.NVarChar).Value = dwData["PTFRAUFKRS"].ToString(); 
          or1.Parameters.Add("PTFRAUFLFD", OracleType.NVarChar).Value = dwData["PTFRAUFLFD"].ToString(); 
          or1.Parameters.Add("PTFRAUFPOS", OracleType.NVarChar).Value = dwData["PTFRAUFPOS"].ToString(); 
          or1.Parameters.Add("PTFRAFOLGE", OracleType.NVarChar).Value = dwData["PTFRAFOLGE"].ToString(); 
          or1.Parameters.Add("PTFKETTANZ", OracleType.NVarChar).Value = dwData["PTFKETTANZ"].ToString(); 
          or1.Parameters.Add("PTFKETTMTR", OracleType.NVarChar).Value = dwData["PTFKETTMTR"].ToString(); 
          or1.Parameters.Add("PTFFILLER", OracleType.NVarChar).Value = dwData["PTFFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
